<?php

class Controller_Task extends Controller_Abstract
{
	function actionA()
	{
		set_time_limit(60*60);
		ini_set('memory_limit', '512M');
		$tmodel = new Task();
		$data = $tmodel->a();
		header('Content-Type: application/csv');
		header('Content-Disposition: attachment; filename="users.csv"');
		$output = fopen('php://output', 'w');
		foreach ($data as &$d)
		{
			$d['ip'] = long2ip($d['ip']);
			$d['created'] = date('Y-m-d', $d['created']);
			if ($d['site_id'] == 1)
			{
				$d['site_id'] = 'cashdazzle.com';
			}
			else if ($d['site_id'] == 2)
			{
				$d['site_id'] = 'lalaloot.com';
			}
			else
			{
				$d['site_id'] = 'mommymoolah.com';
			}
			fputcsv($output, $d);
		}
		fclose($output);
		exit;
	}
	function actionB()
	{
		$tmodel = new Task();
		$data = $tmodel->b();
		header('Content-Type: application/csv');
		header('Content-Disposition: attachment; filename="users.csv"');
		$output = fopen('php://output', 'w');
		foreach ($data as &$d)
		{
			$d['ip'] = long2ip($d['ip']);
			$d['created'] = date('Y-m-d', $d['created']);
			if ($d['site_id'] == 1)
			{
				$d['site_id'] = 'cashdazzle.com';
			}
			else if ($d['site_id'] == 2)
			{
				$d['site_id'] = 'lalaloot.com';
			}
			else
			{
				$d['site_id'] = 'mommymoolah.com';
			}
			fputcsv($output, $d);
		}
		fclose($output);
		exit;
	}
	//this is for email open
	function actionC()
	{
		$tmodel = new Task();
		$data = $tmodel->c();
		header('Content-Type: application/csv');
		header('Content-Disposition: attachment; filename="opens.csv"');
		$output = fopen('php://output', 'w');
		$umodel = new User();
		foreach ($data as &$d)
		{
			$user = $umodel->getUserByField('email', $d['sendto']);
			$d['register'] = date('Y-m-d H:i:s', $user['created']);
			fputcsv($output, $d);
		}
		fclose($output);
		exit;
	}
}

?>